home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / gdevice.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.1 KB  |  161 lines

  1. /*
  2.     File:        GDevice.cp
  3.  
  4.     Contains:    TGDevice is a GDevice utility class, finding out GDevice information.
  5.                   GDevice.cp contains the class body information for the TGDevice class.
  6.  
  7.     Written by: Kent Sandvik    
  8.  
  9.     Copyright:    Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. // Include files
  25. #ifndef _GDEVICE_
  26. #include "GDevice.h"
  27. #endif
  28.  
  29.  
  30. // _________________________________________________________________________________________________________ //
  31. // TGDevice class member function implementations
  32.  
  33. //    CONSTRUCTORS & DESTRUCTORS
  34. #pragma segment GDevice                   
  35. TGDevice::TGDevice()
  36. // The default constructor will just call the IGDevice method which will search
  37. // and hopefully find the GDList (if not the fStatus is false in the class).
  38. {
  39.     fFirstTime = true;                            // indicate we are inside the constructor
  40.     fLast = false;                                // no wrap yet (constructor time)
  41.     Boolean fState = this->IGDevice();            // initialize the object
  42.     fFirstTime = false;                            // out, we are no longer in a cvt
  43.     fFirstGDList = fGDList;                        // record the first in the list
  44. }
  45.  
  46.  
  47. #pragma segment GDevice
  48. TGDevice::~TGDevice()
  49. // Destructor, we are not doing anything inside this one just now.
  50. {
  51. }
  52.  
  53.  
  54. //    INITIATION ROUTINES
  55. #pragma segment GDevice
  56. Boolean TGDevice::IGDevice()
  57. // Look for the GDList, return true if found, false if not.
  58. {
  59.  
  60.     if (fFirstTime)                                // first time we are critical about NULL!
  61.     {
  62.         fGDList = ::GetDeviceList();            // get the device list
  63.         ASSERT(fGDList != NULL, "\pGetDeviceList returned NULL");
  64.  
  65.         this->GetGDeviceValues();                // fill in the proper values ASAP
  66.  
  67.         if (fGDList == NULL)                    // we had a problem
  68.             goto IGDeviceFalse;
  69.         else
  70.             goto IGDeviceOK;                    // OK
  71.     }
  72.     else                                        // we are now called from Next, OK with NULL
  73.         {
  74.             fGDList = ::GetNextDevice(fGDList);    // continue the iteration
  75.  
  76.             if (fGDList == NULL)                // beyond the last one?
  77.             {
  78.                 fGDList = fFirstGDList;            // back to the first one
  79.                 fLast = true;                    // signal this was the last one
  80.                 goto IGDeviceOK;
  81.             }
  82.             goto IGDeviceOK;                    // OK anyway!
  83.         }
  84. IGDeviceFalse:return false;
  85. IGDeviceOK:return true;
  86. }
  87.  
  88.  
  89. #pragma segment GDevice                   
  90. void TGDevice::Next()
  91. // Gets the information from the following devices.
  92. {
  93.     this->IGDevice();
  94.     this->GetGDeviceValues();
  95. }
  96.  
  97.  
  98. #pragma segment GDevice                   
  99. void TGDevice::First()
  100. // Reset to the first GDevice we found.
  101. {
  102.     fGDList = fFirstGDList;
  103. }
  104.  
  105.  
  106. #pragma segment GDevice                   
  107. Ptr TGDevice::GetBase() const
  108. // Return the pointer of the GDevice base, not the address (more flexible that way)
  109. {
  110.     return fBase;
  111. }
  112.  
  113.  
  114. #pragma segment GDevice                   
  115. long TGDevice::GetRow() const
  116. // Return row value.
  117. {
  118.     return fRow;
  119. }
  120.  
  121.  
  122. #pragma segment GDevice                   
  123. short TGDevice::GetDepth() const
  124. // Return the depth level of the GDevice.
  125. {
  126.     return fDepth;
  127. }
  128.  
  129.  
  130. #pragma segment GDevice                   
  131. Boolean TGDevice::Last() const
  132. // Just return the Boolean value if this was the last GDevice or not.
  133. {
  134.     return fLast;
  135. }
  136.  
  137.  
  138. //    PRIVATE MEMBER FUNCTIONS
  139. #pragma segment GDevice
  140. void TGDevice::GetGDeviceValues()
  141. // Get the GDevice information from the GDList device
  142. {
  143.     fBase = (*(*fGDList)->gdPMap)->baseAddr;
  144.  
  145.     fRow = (*(*fGDList)->gdPMap)->rowBytes;
  146.     fRow = fRow & 0x0000FFFF;
  147.  
  148.     fDepth = (*(*fGDList)->gdPMap)->pixelSize;
  149.     fDepth = fDepth & 0x0000FFFF;
  150. }
  151.  
  152.  
  153. // _________________________________________________________________________________________________________ //
  154.  
  155. /*    Change History (most recent last):
  156.   No        Init.    Date        Comment
  157.   1            khs        6/2/92        New file
  158.   2            khs        7/5/92        First decent release
  159.   3            khs        9/7/92        More hacking for multi-dev platform use
  160. */
  161.